package com.nus.fellowmark.common.utils;

import com.alibaba.excel.EasyExcel;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Chen Ruoyi
 * @date 2023/8/25 14:20
 */
public class ExcelUtils {
    public static void download(HttpServletResponse response, Class t, List list, String fileName) throws IOException {
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        EasyExcel.write(response.getOutputStream(), t).sheet("模板").doWrite(list); // using IO stream to write data
    }
}
